package tpi.gui.panels.caso

import dominio.ubicaciones.Pais
import org.apache.wicket.markup.html.form.DropDownChoice
import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.markup.html.panel.Panel
import org.apache.wicket.model.CompoundPropertyModel
import org.apache.wicket.model.PropertyModel
import org.uqbar.commons.model.UserException
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods
import org.uqbar.wicket.xtend.XButton
import tpi.gui.model.Investigacion
import org.apache.wicket.markup.html.panel.FeedbackPanel
import java.util.List
import org.apache.wicket.model.LoadableDetachableModel
import dominio.individuos.Villano
import dominio.investigacion.OrdenDeArresto
import org.uqbar.wicket.xtend.XAttributeModifier
import tpi.gui.pages.caso.ResolverCasoPage

class InterpolPanel extends Panel {
	
	extension WicketExtensionFactoryMethods = new WicketExtensionFactoryMethods
	private final Investigacion investigacion	
	private Villano villanoSeleccionado
		
	new(String id, Investigacion investigacion) {
		super(id)
		this.investigacion = investigacion
		this.defaultModel = investigacion.asCompoundModel
		
		val Form<Investigacion> form = new Form<Investigacion>("interpolForm", new CompoundPropertyModel(this.investigacion))
		form.addChild(new DropDownChoice("villanos", 
			new PropertyModel(this, "villanoSeleccionado"), new PropertyModel(this.investigacion,"caso.expedientes.villanos")
		))
		form.addChild(new XButton("darCaza").onClick = [| emitirOrdenContraVillanoSeleccionado() ])
		addChild(form)
	}
	
	def emitirOrdenContraVillanoSeleccionado() {
		if(villanoSeleccionado == null)
			throw new UserException("Debe elejir un villano antes de perseguirlo :S")
		investigacion.ordenDeArresto = new OrdenDeArresto(villanoSeleccionado)
		villanoSeleccionado = null
		responsePage = new ResolverCasoPage(this.investigacion)
	}
	
}